import Vue from 'vue'
//全局过滤器时间
Vue.filter( 'time' , function(value,format) {
  if(value){
     if(value.toString().length == 10){
          value = value*1000
      }
      var dateObj = new Date(value);
        var date = {
              "Y+": dateObj.getYear(),
              "M+": dateObj.getMonth() + 1,
              "d+": dateObj.getDate(),
              "h+": dateObj.getHours(),
              "m+": dateObj.getMinutes(),
              "s+": dateObj.getSeconds(),
              "q+": Math.floor((dateObj.getMonth() + 3) / 3),
              "S+": dateObj.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (dateObj.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
       }
       return format;
  }
}); 

Vue.filter( 'number' , function(number) {
      if(number>10000){
         return (parseInt(number)/10000).toFixed(2)+"万";
      }else if(number<=10000){
         return number;
      }else{
         return 0;
      } 
}); 

 /*
  * 参数说明：
  * number：要格式化的数字
  * decimals：保留几位小数
  * dec_point：小数点符号
  * thousands_sep：千分位符号
  * len 可以显示数字的长度
  * */
Vue.filter('format',function(number, decimals, dec_point, thousands_sep,len){
    let length = (typeof len === 'undefined') ? 6: len;
    if(number>0){
        if(number.toString().length>length){
            if(number>10000){
              return (parseInt(number)/10000).toFixed(0)+"W";
            }else{
              return number;
            }
        }else{
            number = (number + '').replace(/[^0-9+-Ee.]/g, '');
            var n = !isFinite(+number) ? 0 : +number,

                prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
                dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                s = '',
                toFixedFix = function (n, prec) {
                    var k = Math.pow(10, prec);
                    return '' + Math.floor(n * k) / k;
                };
            s = (prec ? toFixedFix(n, prec) : '' + Math.floor(n)).split('.');
            var re = /(-?\d+)(\d{3})/;
            //console.log(s)
            while (re.test(s[0])) {
                s[0] = s[0].replace(re, "$1" + sep + "$2");
            }

            if ((s[1] || '').length < prec) {
                s[1] = s[1] || '';
                s[1] += new Array(prec - s[1].length + 1).join('0');
            }
            return s.join(dec);
        }
    }else{
        return '0.00'
    }
})

Vue.filter( 'head' , function(head) {
      if(!head){
         return 'http://oslg9bt6h.bkt.clouddn.com/default-img1.png';
      }else{
         return head;
      } 
}); 

Vue.filter( 'matchStatus' , function(status) {
    switch (status){ 
      case 0 : return "未开始"; break; 
      case 1 : return "报名中"; break; 
      case 2 : return "比赛中"; break; 
      case 3 : return "已结束"; break; 
      case 4 : return "已结算"; break; 
      case 9 : return "已终止"; break; 
    } 
}); 